<template>
  <div>
    <h3>用户表信息</h3>
    <button class="btn btn-primary" @click="add()">
      增加
    </button>
    <table class="table">
      <tr>
        <th>表号</th>
        <th>卡号</th>
        <th>表牌</th>
        <th>计量类型</th>
        <th>表径</th>
        <th>机表读数</th>
        <th>剩余气量</th>
        <th>总气量</th>
        <th>累购</th>
        <th>备注</th>
        <th>修改</th>
        <th>删除</th>
       </tr>
       <tr v-for = "row in model.rows">
         <td>{{row.f_meter_no}}</td>
         <td>{{row.f_card_id}}</td>
         <td>{{row.f_meter_brand}}</td>
         <td>{{row.f_meter_measurement}}</td>
         <td>{{row.f_meter_diameter}}</td>
         <td>{{row.f_meter_reading}}</td>
         <td>{{row.f_meter_remain}}</td>
         <td>{{row.f_meter_total}}</td>
         <td>{{row.f_meter_accumulation}}</td>
         <td>{{row.f_remark}}</td>
         <td class="nopadding">
           <a   @click='change(row)'>修改</a>
         </td>
         <td class="nopadding">
           <a   @click='del(row, $index)'>删除</a>
         </td>
       </tr>

    </table>

  </div>
</template>

<script>
// import { PagedList } from 'vue-client'
import co from 'co'
let info = function * (self) {
  self.f_user_id = self.user.f_user_id
  self.f_userfile_id = self.user.id
  let back = yield self.$post('rs/sql/用户表档案', {data: {f_user_id: self.f_user_id,
    f_userfile_id: self.f_userfile_id}}, {resolveMsg: null, rejectMsg: null})
  self.model.rows = back.data
  // self.$back()
}

export default {
  title: '用户表档案',
  props: ['user', 'f', 'flag'],
  data () {
    return {
    //   model: new PagedList('rs/sql/用户表档案', 20, {f_user_id: this.user.f_user_id,
    // f_userfile_id: this.user.id})
      model: {
        rows: []
      },
      f_user_id: '',
      f_userfile_id: ''
    }
  },
  methods: {
    change (row) {
      this.$goto('metterfiles-change', {row: row})
    },
    add () {
      this.flag = false
      this.$goto('metterfiles-add', {ro: this.user}, 'self', this.callback)
    },
    del (row, index) {
      this.$post('rs/logic/删除表档案', {data: row}, {resolveMsg: null, rejectMsg: null})
      this.model.rows.splice(index, 1)
    },
    callback () {
      let infomathis = info(this)
      return co(infomathis)
    }
  },
  ready () {
    let infomathis = info(this)
    return co(infomathis)
  },
  watch: {
    'user' (val) {
      let infomathis = info(this)
      return co(infomathis)
    },
    'flag' (val) {
      let infomathis = info(this)
      return co(infomathis)
    }
  }
}
</script>
